package vooga.core;

import sun.audio.*;    //import the sun.audio package
import java.net.*;
import java.io.*;

    
/**
 * This class handles playing sounds.
 *
 * Only the following formats are supported: wav, aiff, au, mid, rmf.
 *
 * @author Robert C. Duvall
 */
public class Sound
{
    private AudioStream myData;


    public Sound (String name)
    {
        try
        {
            myData = new AudioStream(new FileInputStream(name));
        }
        catch (Exception e)
        {
            System.out.println("Bad sound file given " + name);
            e.printStackTrace();
        }
    }

    public Sound (URL url)
    {
        try
        {
            myData = new AudioStream(url.openStream());
        }
        catch (Exception e)
        {
            System.out.println("Bad sound file given " + url);
            e.printStackTrace();
        }
    }


    public void play ()
    {
        try
        {
            AudioPlayer.player.start(myData);
        }
        catch (Exception e)
        {
            // nothing can be done
            e.printStackTrace();
        }
    }

    public void stop ()
    {
        try
        {
            AudioPlayer.player.stop(myData);
        }
        catch (Exception e)
        {
            // nothing can be done
            e.printStackTrace();
        }
    }
}
